package com.thinvent.remotepassword.util;

import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

import java.io.IOException;

public class OkHttpUtil {

    private final OkHttpClient client = new OkHttpClient();

    /**
     * 发送GET请求并返回响应体内容。
     * @param url 请求的URL
     * @return 响应体中的字符串内容
     * @throws IOException 网络请求或读取响应时可能发生的异常
     */
    public String doGet(String url) throws IOException {
        Request request = new Request.Builder()
                .url(url)
                .build();

        try (Response response = client.newCall(request).execute()) {
            if (!response.isSuccessful()) {
                throw new IOException("GET request failed with error code: " + response.code());
            }
            return response.body().string();
        }
    }

    public static void main(String[] args) throws IOException {
//        double[][] doubles1 = SimilarityUtil.getVet("修改密码");
//
//        double[][] doubles2 = SimilarityUtil.getVet("我如何修改密码");
//
//        double similarity = SimilarityUtil.cosineSimilarity(doubles1, doubles2);
//        System.out.println("Cosine Similarity: " + similarity);
    }

}
